<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header"
           style="display: flex;justify-content: space-between;width: 100%;font-size: 16px;align-items: center;">
        <span>车辆详情</span>
        <el-button @click="pageReturn">返回</el-button>
      </div>
      <div class="top-card">
<!--        <el-image src="" style="width: 100px; height: 100px"></el-image>-->
        <div class="top-card-right">
          <div style="font-size: 16px;display: flex;justify-content: space-between; ">
            <div>
              <span style="font-weight: 600">车架号：</span><span>{{ detailForm.vinNo }}</span>
            </div>
            <div>
              <span style="font-weight: 600">车辆状态：</span><span>
                {{ selectDictLabel(dict.type.car_business_type, detailForm.businessType) }}</span>
            </div>
          </div>
          <div>
            <span>品牌/车型/车款：</span>
            <span>{{
                `${detailForm.brandName ? detailForm.brandName : ""}
                ${detailForm.seriesName ? detailForm.seriesName + "/" : ""}
                ${detailForm.modelName ? detailForm.modelName + "/" : ""}`
              }}</span>
          </div>
          <div>
            <span>车辆归属：</span><span>{{ detailForm.ascription }}</span>
          </div>
        </div>
      </div>
    </el-card>

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="更换轮胎详情" name="ghltxq">
        <el-form :model="detailForm" v-if="isForm" class="el-form">
          <el-card class="box-card">
            <div slot="header" class="header-card">
              <span class="header-card-title">车辆信息</span>
            </div>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="车辆订单:">
                  <span>{{ detailForm.orderNo }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="客户名称:">
                  <span>{{ detailForm.customerName }}</span>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="租赁合同日期:">
                  {{ detailForm.leaseStartTime }} ~
                  {{ detailForm.leaseEndTime }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="租赁台数:">
                  <span>{{ detailForm.leaseNum }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="车辆行驶里程:">
                  <span>{{ detailForm.travelMeligile }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="注册日期:">
                  <span>{{ detailForm.registerTime }}</span>
                </el-form-item>
              </el-col>
            </el-row>
<!--            <el-row :gutter="20">-->
<!--              <el-col :span="8">-->
<!--                <el-form-item label="预算费用:">-->
<!--                  <span>{{-->
<!--                      format_thousand(detailForm.bicycleBudgetPrice)-->
<!--                    }}</span>-->
<!--                </el-form-item>-->
<!--              </el-col>-->
<!--              <el-col :span="8">-->
<!--                <el-form-item label="已更换轮胎成本:">-->
<!--                  <span>{{ format_thousand(detailForm.replacePrice) }}</span>-->
<!--                </el-form-item>-->
<!--              </el-col>-->
<!--              <el-col :span="8">-->
<!--                <el-form-item label="剩余预估费用:">-->
<!--                  <span>{{-->
<!--                      format_thousand(detailForm.carSurplusPrice)-->
<!--                    }}</span>-->
<!--                </el-form-item>-->
<!--              </el-col>-->
<!--            </el-row>-->
          </el-card>
          <el-card class="box-card">
            <div slot="header" class="header-card">
              <span class="header-card-title">更换轮胎信息</span>
            </div>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="预计更换轮胎开始时间:">
                  <span>{{
                      detailForm.expectStartTime
                    }}</span>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="预计更换轮胎结束时间:">
                  <span>{{ detailForm.expectEndTime }}</span>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="签约更换轮胎厂:">
                  <span>{{
                      detailForm.maintenanceShop
                    }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="故障现象:">
                  <span>{{
                      detailForm.faultPhenomenon
                    }}</span>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="更换轮胎厂故障诊断:">
                  <span>{{
                      detailForm.maintenanceFaultDiagnosis
                    }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="更换轮胎厂报价:">
                  <span>{{
                      format_thousand(detailForm.maintenanceQuoter)
                    }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否符合索赔理由:">
                  <span>{{
                      detailForm.reasonForClaim == "1"
                          ? "是"
                          : detailForm.reasonForClaim == "2"
                              ? "否"
                              : ""
                    }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8" v-if="detailForm.reasonForClaim == '2'">
                <el-form-item label="不符合索赔理由:">
                  <span>{{ detailForm.claimantReason }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否有同车型（处置车辆）对换配件:">
                  <span>{{
                      detailForm.swappingAccessories == "1"
                          ? "是"
                          : detailForm.swappingAccessories ==
                          "2"
                              ? "否"
                              : ""
                    }}</span>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col>
                <el-form-item label="综合建议方案:">
                  <span>{{
                      detailForm.comprehensiveRecommendations
                    }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="备注:">
                  <span>{{ detailForm.normalRemark }}</span>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
          <el-card class="box-card">
            <div slot="header" class="header-card">
              <span class="header-card-title">更换轮胎项目明细</span>
            </div>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="旧轮胎行驶里程:">
                  <span>{{
                      detailForm.oldTyreMeligile
                    }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否调换备胎:">
                  <span>{{
                      detailForm.isReplaceSpareTire == "1"
                          ? "是"
                          : detailForm.isReplaceSpareTire ==
                          "2"
                              ? "否"
                              : ""
                    }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="品牌:">
                  <span>{{ detailForm.tyreBrand }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="型号:">
                  <span>{{ detailForm.tyreModel }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="花纹:">
                  <span>{{ detailForm.tyreFigure }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="载重指数速度级别:">
                  <span>{{ detailForm.leadSpeedLevel }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="单价（含税）:">
                  <span>{{ format_thousand(detailForm.unitPrice) }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="轮胎数量（条）:">
                  <span>{{ detailForm.tyreNum }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="合计费用:">
                  <span>{{ format_thousand(detailForm.totalPrice) }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="备注:">
                  <span>{{ detailForm.tyreRemark }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col style="margin-top: 16px">
                <el-form-item label="查看附件:">
                  <image-common v-model="detailForm.annexUrl" :disabled="true" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </el-form>
      </el-tab-pane>

      <el-tab-pane label="更换轮胎记录" name="ghltjl">
        <el-card class="box-card">
          <el-row :gutter="20">
            <el-form>
              <el-col :span="8">
                <el-form-item label="车辆更换轮胎总次数:">
                  <span>{{ form.totalCount }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="车辆更换轮胎总金额:">
                  <span>{{ format_thousand(form.totalMoney) }}</span>
                </el-form-item>
              </el-col>
<!--              <el-col :span="8">-->
<!--                <el-form-item label="车辆剩余预估费用:">-->
<!--                  <span>{{ format_thousand(form.bicycleBudgetPrice) }}</span>-->
<!--                </el-form-item>-->
<!--              </el-col>-->
            </el-form>
          </el-row>

          <el-row :gutter="20">
            <el-col>
              <el-table :data="tableData" border style="width: 100%">
                <el-table-column label="操作" fixed align="center" width="100">
                  <template #default="{row}">
                    <el-button type="text" @click="handleRoute(row)">查看</el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="oldTyreMeligile" show-overflow-tooltip min-width="100" align="center" label="旧轮胎使用里程">
                </el-table-column>
                <el-table-column prop="customerName" show-overflow-tooltip min-width="100" align="center" label="客户名称">
                </el-table-column>
                <el-table-column prop="expectStartTime" show-overflow-tooltip min-width="100" align="center" label="预计开始时间">
                </el-table-column>
                <el-table-column prop="expectEndTime" show-overflow-tooltip min-width="100" align="center" label="预计结束时间">
                </el-table-column>
                <el-table-column prop="actualStartTime" show-overflow-tooltip min-width="100" align="center" label="实际开始时间">
                </el-table-column>
                <el-table-column prop="actualEndTime" show-overflow-tooltip min-width="100" align="center" label="实际结束时间">
                </el-table-column>
                <el-table-column prop="ascription" show-overflow-tooltip min-width="100" align="center" label="车辆归属">
                </el-table-column>
                <el-table-column prop="propertyRightName" show-overflow-tooltip min-width="100" align="center" label="车辆产权">
                </el-table-column>
                <el-table-column prop="totalPrice" show-overflow-tooltip min-width="100" align="center" label="更换轮胎费用">
                  <template #default="{row}">
                    {{format_thousand(row.totalPrice)}}
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
          </el-row>
        </el-card>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import imgList from "../imgList.vue";
import {getToken} from "@/utils/auth";
import {
  getInsuranceDetails,
  getDetails,
  queryPageRecord,
} from "@/api/zcwh/ghltApi.js";
import {getChangeWheelMessage} from "@/api/zcwh/vehicleTabs.js";

export default {
  name: "ghltDetails",
  dicts: ["car_business_type"],
  components: {imgList},
  computed: {},
  data() {
    return {
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carId: "2",
        maintenanceType: "2",
      },

      total: 0,
      isForm: false,
      routeQuery: {},
      activeName: "ghltxq",
      detailForm: {},
      tableData: [],
      form: {},
    };
  },
  watch: {},
  created() {
    if(this.$route.query.id){
      this.getDetails(this.$route.query.id);
    }
    this.queryPageRecord();
  },
  methods: {
    handleRoute(row){
      this.activeName = "ghltxq"
      this.getDetails(row.carReplaceTyreId);
    },
    queryPageRecord() {
      queryPageRecord({carId: "1"}).then((res) => {
      });
    },
    pageReturn() {
      this.$tab.closePage().then(({visitedViews}) => {
        this.$router.push({
          path: "/clgl/ghltList",
        });
      });
    },
    handleClick(tab, event) {
      if (this.activeName == "ghltjl") {
        this.handleList();
      }
    },
    getDetails(id) {
      getDetails(id).then((res) => {
        if (res.code == "200") {
          this.detailForm = res.data || {};

          this.isForm = true;
        }
      });
    },
    handleList() {
      this.loading = true;
      getChangeWheelMessage(this.detailForm.carId)
          .then((res) => {
            this.form = res;
            this.tableData = res.vo;
            this.loading = false;
          })
          .finally(() => {
            this.loading = false;
          });
    },
    recordList() {
      recordList({carId: "5"}).then((res) => {
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.box-card {
  font-size: 14px;
  margin-bottom: 20px;

  .box-card-inp {
    display: flex;
    align-items: center;
    margin-bottom: 20px;

    .inp-name {
      width: 140px;
      text-align: right;
      font-size: 14px;
    }

    .inp-name-r {
      flex: 1;
    }
  }

  .top-card {
    display: flex;

    img {
      display: block;
      width: 200px;
      height: 160px;
    }

    .top-card-right {
      flex: 1;
      margin-left: 20px;
      font-size: 14px;
      line-height: 36px;
    }
  }

  ::v-deep .el-card__header {
    padding: 0;
    height: 48px;
    margin: 0 14px;
    display: flex;
    align-items: center;

    .header-card {
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex: 1;

      .header-card-title {
        font-size: 16px;
        font-weight: 500;
        color: #333333;
      }
    }
  }

  ::v-deep .el-card__body {
    padding: 10px 14px;
  }
}

.el-form {
  ::v-deep.el-form-item {
    display: flex;
  }

  ::v-deep .el-form-item {
    margin-bottom: 12px;
  }

  ::v-deep.el-form-item__content {
    line-height: normal;
    flex: 1;
    margin-left: 0 !important;
  }

  ::v-deep.el-form-item__label {
    line-height: normal;
    font-size: 14px;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    color: #646464;
  }
}
</style>
